/*
 * ProxyWindow.java
 *
 * Created on March 28, 2008, 3:36 PM
 */

package imessenger;

import ymsg.network.*;
import ymsg.network.event.*;
import ymsg.support.*;
import ymsg.test.*;
/**
 *
 * @author  Shelley Jane C. Co
 */
public class ProxyWindow extends javax.swing.JFrame {
    
    public boolean isProxy;
    
    /** Creates new form ProxyWindow */
    public ProxyWindow() 
    {
        this.isProxy = false;
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        proxyPanel = new javax.swing.JPanel();
        hostLbl = new javax.swing.JLabel();
        hostTxtBx = new javax.swing.JTextField();
        portLbl = new javax.swing.JLabel();
        portTxtBx = new javax.swing.JTextField();
        okBtn = new javax.swing.JButton();
        cancelBtn = new javax.swing.JButton();
        noProxy = new javax.swing.JRadioButton();
        yesProxy = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        proxyPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Proxy Settings"));
        proxyPanel.setEnabled(false);
        proxyPanel.setFocusable(false);

        hostLbl.setText("Proxy Host:");
        hostLbl.setEnabled(false);

        hostTxtBx.setEnabled(false);

        portLbl.setText("Proxy Port:");
        portLbl.setEnabled(false);
        portLbl.setInheritsPopupMenu(false);

        portTxtBx.setEnabled(false);

        javax.swing.GroupLayout proxyPanelLayout = new javax.swing.GroupLayout(proxyPanel);
        proxyPanel.setLayout(proxyPanelLayout);
        proxyPanelLayout.setHorizontalGroup(
            proxyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, proxyPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(proxyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(hostLbl)
                    .addComponent(portLbl))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(proxyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(portTxtBx)
                    .addComponent(hostTxtBx, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)))
        );
        proxyPanelLayout.setVerticalGroup(
            proxyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(proxyPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(proxyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(hostTxtBx, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(hostLbl))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(proxyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(portTxtBx, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(portLbl))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        okBtn.setText("OK");
        okBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okBtnActionPerformed(evt);
            }
        });

        cancelBtn.setText("Cancel");
        cancelBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelBtnActionPerformed(evt);
            }
        });

        noProxy.setSelected(true);
        noProxy.setText("No Proxy");
        noProxy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                noProxyActionPerformed(evt);
            }
        });

        yesProxy.setText("Use Proxy");
        yesProxy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                yesProxyActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(proxyPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                        .addGap(26, 26, 26))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(yesProxy)
                                    .addComponent(noProxy))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 151, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(okBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addComponent(cancelBtn)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(noProxy)
                .addGap(3, 3, 3)
                .addComponent(yesProxy)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
                .addComponent(proxyPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelBtn)
                    .addComponent(okBtn))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void yesProxyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yesProxyActionPerformed
        // TODO add your handling code here:
        if (!this.isProxy)
        {
            this.noProxy.setSelected(false);
            this.isProxy = true;
            this.proxyPanel.setEnabled(true);
            
            this.hostLbl.setEnabled(true);
            this.hostTxtBx.setEnabled(true);
            this.hostTxtBx.setEditable(true);

            this.portLbl.setEnabled(true);
            this.portTxtBx.setEnabled(true);
            this.portTxtBx.setEditable(true);
        }
        
}//GEN-LAST:event_yesProxyActionPerformed

    private void noProxyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_noProxyActionPerformed
        // TODO add your handling code here:
        
        if (this.isProxy)
        {
            this.yesProxy.setSelected(false);
            this.isProxy = false;
            this.proxyPanel.setEnabled(false);

            this.hostLbl.setEnabled(false);
            this.hostTxtBx.setEnabled(false);
            this.hostTxtBx.setEditable(false);

            this.portLbl.setEnabled(false);
            this.portTxtBx.setEnabled(false);
            this.portTxtBx.setEditable(false);
        }
    }//GEN-LAST:event_noProxyActionPerformed

    private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed
        // TODO add your handling code here:
        this.isProxy = false;
        this.dispose();
    }//GEN-LAST:event_cancelBtnActionPerformed

    private void okBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okBtnActionPerformed
        // TODO add your handling code here:
        if (this.isProxy)
        {
            if(this.hostTxtBx.getText().equals("") || this.portTxtBx.getText().equals(""))
            {
                System.out.println("Proxy host or port is empty!");
            }
            else
            {
                //String host = this.getHostTxtBx().getText();
                //int port = Integer.parseInt(this.getPortTxtBx().getText());

                this.setVisible(false);
            }
        }
        else
            this.dispose();
        
    }//GEN-LAST:event_okBtnActionPerformed

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelBtn;
    private javax.swing.JLabel hostLbl;
    private javax.swing.JTextField hostTxtBx;
    private javax.swing.JRadioButton noProxy;
    private javax.swing.JButton okBtn;
    private javax.swing.JLabel portLbl;
    private javax.swing.JTextField portTxtBx;
    private javax.swing.JPanel proxyPanel;
    private javax.swing.JRadioButton yesProxy;
    // End of variables declaration//GEN-END:variables

    public String getHost() {
        return hostTxtBx.getText();
    }

    public String getPort() {
        return portTxtBx.getText();
    }

    
}
